#include"queue.h"
void init(queue* ps)
{
	ps->phead = NULL;
	ps->ptail = NULL;
	ps->size = 0;
}
void push(queue* ps, datatype x)
{
	assert(ps);

	quenode* newndoe = (quenode*)malloc(sizeof(quenode));
	newndoe->val = x;
	newndoe->next = NULL;
	
	if (ps->phead == NULL)
	{
		ps->phead = ps->ptail = newndoe;
	}
	else
	{
		ps->ptail->next = newndoe;
		ps->ptail = newndoe;
	}
	ps->size++;
}
void pop(queue* ps)
{
	assert(ps);
	assert(ps->phead != NULL);
	if (ps->size == 1)
	{
		free(ps->phead);
		ps->phead = ps->ptail = NULL;
	}
	else
	{
		quenode* cur = ps->phead->next;
		free(ps->phead);
		ps->phead = cur;
	}
	ps->size--;
}
datatype top(queue* ps)
{
	assert(ps);
	assert(ps->phead != NULL);
	return ps->phead->val;
}
bool empty(queue* ps)
{
	return ps->size == 0;
}
int size(queue* ps)
{
	return ps->size;
}
void print(queue* ps)
{
	quenode* cur = ps->phead;
	while (cur)
	{
		printf("%d ",cur->val);
		cur = cur->next;
	}
}